package ysf.com.mediumdifficulty;

import java.util.LinkedList;
import java.util.List;

/**
 * @author ysf
 * @date 2021/7/5 22:21
 */
public class SeventeenthDemos {

    public static void main(String[] args) {
        String input = "234";
        List<String> stringList = letterCombinations(input);
        System.out.println(stringList);

    }
    public static List<String> letterCombinations(String digits) {
        LinkedList<String> ans = new LinkedList<>();
        if (digits.isEmpty()) {
            return ans;
        }
        String[] mapping = new String[]{"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        ans.add("");

        for (int i = 0; i < digits.length(); i++) {
            int x = Character.getNumericValue(digits.charAt(i));

            // 获取Linkedlist链表集合中的第一个元素
            String peek = ans.peek();
            int length = ans.peek().length();

            while (ans.peek().length() == i) {
                // 查看元素出队
                String t = ans.remove();
                char[] chars = mapping[x].toCharArray();
                for (char s : chars) {
                    ans.add(t + s);
                }
            }
        }
        return ans;

    }


}
